#include <pspctrl.h>
#include "TGALoader.h"

void CheckButtons()
{
    if(pd.Buttons & PSP_CTRL_LEFT)
        MonkeyTurnLeft();
    else if(pd.Buttons & PSP_CTRL_RIGHT)
        MonkeyTurnRight();
    else
        Monkey.State = MONKEY_NORM;

    if(pd.Buttons & PSP_CTRL_CROSS)
        MonkeyJump();
    else
        MonkeyNoJump();
}

int buttonListener(SceSize args, void* argp)
{
    while(1)
    {
        sceCtrlReadBufferPositive(&pd, 1);

        if(pd.Buttons & PSP_CTRL_CIRCLE)
            sceKernelExitGame();
        
        if(step == 2) //MAINMENU
        {
            if(pd.Buttons & PSP_CTRL_UP)
            {
                if(mm_selected == 4)
                    mm_selected = 1;
                else
                    mm_selected++;
            } else if(pd.Buttons & PSP_CTRL_DOWN)
            {
                if(mm_selected == 1)
                    mm_selected = 4;
                else
                    mm_selected--;
            } else if(pd.Buttons & PSP_CTRL_CROSS)
            {
                switch(mm_selected)
                {
                    case 1:
                        sceKernelExitGame();
                        break;
                    case 2:
                        step = 3;
                        break;
                    case 4:
                        step = 5;
                        break;
                }
                mm_selected = 4;
            }

        } else if(step == 3) //CREDITS
            if(pd.Buttons & PSP_CTRL_SQUARE)
                step = 2;
        
        if(step != 5)
            sceKernelDelayThread(110000);
        else
            sceKernelDelayThread(10000);
    }
    return 1;
}